<script setup>
import { ref } from 'vue'

const artworks = ref([
  {
    id: 1,
    title: '海浪律动',
    author: '声音艺术家',
    date: '2024-02-20',
    duration: '3:45',
    views: 1280,
    likes: 326,
    cover: 'https://images.pexels.com/photos/1738434/pexels-photo-1738434.jpeg?auto=compress&cs=tinysrgb&w=1600',
    effect: '波浪',
    tags: ['海洋', '冥想', '自然']
  },
  {
    id: 2,
    title: '星空交响',
    author: '夜空漫游者',
    date: '2024-02-18',
    duration: '4:20',
    views: 2150,
    likes: 528,
    cover: 'https://images.pexels.com/photos/1694000/pexels-photo-1694000.jpeg?auto=compress&cs=tinysrgb&w=1600',
    effect: '星空',
    tags: ['宇宙', '梦幻', '夜晚']
  },
  {
    id: 3,
    title: '城市脉动',
    author: '都市声音师',
    date: '2024-02-15',
    duration: '5:10',
    views: 1680,
    likes: 425,
    cover: 'https://images.pexels.com/photos/3052361/pexels-photo-3052361.jpeg?auto=compress&cs=tinysrgb&w=1600',
    effect: '频谱',
    tags: ['城市', '节奏', '现代']
  }
])

const filters = ref({
  sort: 'newest',
  effect: 'all',
  duration: 'all'
})

const selectedArtwork = ref(null)

const showArtworkDetail = (artwork) => {
  selectedArtwork.value = artwork
}
</script>

<template>
  <div class="gallery-container">
    <div class="gallery-header">
      <div class="header-content">
        <h1>作品展示</h1>
        <div class="filter-controls">
          <div class="filter-group">
            <label>排序</label>
            <select v-model="filters.sort">
              <option value="newest">最新发布</option>
              <option value="popular">最受欢迎</option>
              <option value="views">播放最多</option>
            </select>
          </div>
          <div class="filter-group">
            <label>效果</label>
            <select v-model="filters.effect">
              <option value="all">全部效果</option>
              <option value="wave">波浪</option>
              <option value="particle">粒子</option>
              <option value="spectrum">频谱</option>
            </select>
          </div>
          <div class="filter-group">
            <label>时长</label>
            <select v-model="filters.duration">
              <option value="all">全部时长</option>
              <option value="short">3分钟以下</option>
              <option value="medium">3-5分钟</option>
              <option value="long">5分钟以上</option>
            </select>
          </div>
        </div>
      </div>
      <div class="search-bar">
        <input type="text" placeholder="搜索作品名称、作者或标签...">
        <button class="search-btn">搜索</button>
      </div>
    </div>

    <div class="artworks-grid">
      <div 
        v-for="artwork in artworks"
        :key="artwork.id"
        class="artwork-card"
        @click="showArtworkDetail(artwork)"
      >
        <div class="artwork-cover">
          <img :src="artwork.cover" :alt="artwork.title">
          <div class="artwork-duration">{{ artwork.duration }}</div>
          <div class="artwork-overlay">
            <button class="play-btn">▶</button>
          </div>
        </div>
        <div class="artwork-info">
          <h3>{{ artwork.title }}</h3>
          <p class="artwork-author">{{ artwork.author }}</p>
          <div class="artwork-stats">
            <span>{{ artwork.views }} 次播放</span>
            <span>{{ artwork.likes }} 赞</span>
          </div>
          <div class="artwork-tags">
            <span 
              v-for="(tag, index) in artwork.tags"
              :key="index"
              class="tag"
            >
              {{ tag }}
            </span>
          </div>
        </div>
      </div>
    </div>

    <!-- 作品详情弹窗 -->
    <div v-if="selectedArtwork" class="artwork-detail-modal" @click="selectedArtwork = null">
      <div class="modal-content" @click.stop>
        <button class="close-btn" @click="selectedArtwork = null">×</button>
        <div class="artwork-preview">
          <img :src="selectedArtwork.cover" :alt="selectedArtwork.title">
          <button class="play-btn large">▶</button>
        </div>
        <div class="artwork-detail">
          <h2>{{ selectedArtwork.title }}</h2>
          <div class="author-info">
            <img src="https://images.pexels.com/photos/614810/pexels-photo-614810.jpeg?auto=compress&cs=tinysrgb&w=100" 
                 alt="author avatar" 
                 class="author-avatar">
            <div class="author-meta">
              <span class="author-name">{{ selectedArtwork.author }}</span>
              <span class="publish-date">{{ selectedArtwork.date }}</span>
            </div>
          </div>
          <div class="artwork-stats detailed">
            <div class="stat-item">
              <span class="stat-icon">👁️</span>
              <span class="stat-value">{{ selectedArtwork.views }}</span>
              <span class="stat-label">播放</span>
            </div>
            <div class="stat-item">
              <span class="stat-icon">❤️</span>
              <span class="stat-value">{{ selectedArtwork.likes }}</span>
              <span class="stat-label">赞</span>
            </div>
            <div class="stat-item">
              <span class="stat-icon">⏱️</span>
              <span class="stat-value">{{ selectedArtwork.duration }}</span>
              <span class="stat-label">时长</span>
            </div>
          </div>
          <div class="artwork-tags detailed">
            <span 
              v-for="(tag, index) in selectedArtwork.tags"
              :key="index"
              class="tag"
            >
              {{ tag }}
            </span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.gallery-container {
  min-height: calc(100vh - 72px);
  padding: 20px;
  max-width: 1800px;
  margin: 0 auto;
}

.gallery-header {
  background: white;
  border-radius: 16px;
  padding: 32px;
  margin-bottom: 32px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.gallery-header h1 {
  font-size: 28px;
  color: #4a4a4a;
  background: linear-gradient(45deg, #6366f1, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.filter-controls {
  display: flex;
  gap: 24px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-group label {
  font-size: 14px;
  color: #666;
}

.filter-group select {
  padding: 8px 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
  outline: none;
  min-width: 160px;
}

.search-bar {
  display: flex;
  gap: 16px;
}

.search-bar input {
  flex: 1;
  padding: 12px 20px;
  border: 1px solid #ddd;
  border-radius: 8px;
  outline: none;
  font-size: 16px;
}

.search-btn {
  padding: 12px 24px;
  background: #6366f1;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
}

.search-btn:hover {
  background: #4f46e5;
}

.artworks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 24px;
}

.artwork-card {
  background: white;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: transform 0.3s;
}

.artwork-card:hover {
  transform: translateY(-4px);
}

.artwork-cover {
  position: relative;
  aspect-ratio: 16/9;
  overflow: hidden;
}

.artwork-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.artwork-duration {
  position: absolute;
  bottom: 12px;
  right: 12px;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border-radius: 4px;
  font-size: 12px;
}

.artwork-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
}

.artwork-card:hover .artwork-overlay {
  opacity: 1;
}

.play-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #6366f1;
  cursor: pointer;
  transition: transform 0.3s;
}

.play-btn:hover {
  transform: scale(1.1);
}

.play-btn.large {
  width: 80px;
  height: 80px;
  font-size: 32px;
}

.artwork-info {
  padding: 20px;
}

.artwork-info h3 {
  font-size: 18px;
  color: #4a4a4a;
  margin-bottom: 8px;
}

.artwork-author {
  color: #666;
  margin-bottom: 12px;
}

.artwork-stats {
  display: flex;
  gap: 16px;
  color: #666;
  font-size: 14px;
  margin-bottom: 12px;
}

.artwork-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag {
  padding: 4px 12px;
  background: #f6f7fb;
  border-radius: 16px;
  font-size: 12px;
  color: #666;
}

.artwork-detail-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  border-radius: 16px;
  width: 90%;
  max-width: 1200px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: none;
  border: none;
  font-size: 24px;
  color: white;
  cursor: pointer;
  z-index: 1;
}

.artwork-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
}

.artwork-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.artwork-detail {
  padding: 32px;
}

.artwork-detail h2 {
  font-size: 24px;
  color: #4a4a4a;
  margin-bottom: 20px;
}

.author-info {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.author-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
}

.author-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.author-name {
  font-weight: 500;
  color: #4a4a4a;
}

.publish-date {
  font-size: 14px;
  color: #666;
}

.artwork-stats.detailed {
  display: flex;
  gap: 32px;
  margin-bottom: 24px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-icon {
  font-size: 24px;
}

.stat-value {
  font-weight: 500;
  color: #4a4a4a;
}

.stat-label {
  font-size: 12px;
  color: #666;
}

.artwork-tags.detailed {
  margin-top: 24px;
}

.artwork-tags.detailed .tag {
  font-size: 14px;
  padding: 6px 16px;
}

@media (min-width: 1920px) {
  .artworks-grid {
    grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  }
}
</style> 